<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:useBean id="now" class="java.util.Date" />
<style type="text/css">
 div.txbc_container{width: 100%;height: 100%;background-color: #ffffff;min-height: 650px;}
 .page_calendar_input{background-color: #ffffff !important;}
 div.txbc_content_title{background-color: #21c6b6;line-height: 40px;color: #ffffff;text-align: center;}
 table.txbc_table{min-height: 650px;margin-bottom: 0px;}
 #tx_bcjl_content{padding: 10px;margin-bottom: 35px;}
 button.btn_txbc_add{background-color:#57b4ea !important;float: right;margin-right: 20px;}
 button.btn_txbc_del{float: right;}
 div.btn_txbcmuban_set{position: absolute;bottom: 8px;right: 8px;background-color: #21c6b6;padding: 6px 12px;border-radius: 4px;cursor: pointer;color: #ffffff;}
 .txbc_tr_active{background-color: #21c7b6 !important;}
 .table-bordered>thead>tr>td,.table-bordered>tbody>tr>td{text-align: center;cursor: default;}
 #tx_bcjl_content{
 	background:#FFF;
 	height:556px;
 	overflow:auto;
 	border-radius:0 0 4px 4px;
 	border:1px solid #ddd;
 	border-top:0;
 	font-size:15px;
 	white-space: pre-wrap;
	word-wrap: break-word;
	max-width:780px;
	margin:0 auto;
 }
 
 div.break-br{
 	width:0;
 	height:0;
 	display:none;
 }
 @media screen and (max-width: 1800px) {
    div.break-br {
        display:block;
        width:100px;
        height:6px;
    }
    .btn_txbc_add,.btn_txbc_print,.btn_txbc_del{
    	width:82px;
    	margin:2px 0 6px 20px !important;
    }
}
 .tx_bcjl_table input[type="checkbox"]{
 	width:17px;
 	height:17px;
 }
 .btn_txbc_add,.btn_txbc_print,.btn_txbc_del{
    	width:70px;
    	margin:2px 0 6px 20px !important;
    }
 .btn_txbc_print{
 	float:right;
 }
 #print_wrapper,#print_wrapper_clone {
            width: 210mm;
            margin: 0 auto;
            font-size: 14px;
			position: relative;
			top:0;
			left:0;
        }
</style>
   <div class="txbc_container">
      <table class="table txbc_table">
       <tr>
       
        <td width="52%">
          <div style="padding: 8px 0px;">
			<label class="bcjl-head" style="margin-right: 15px;margin-bottom: 0px;"> 
			     查询日期&nbsp;&nbsp;
			  <div class="page_calendar_div"><input type="text" id="tx_start_time" class="page_calendar_input datetime_ymd_start" name="start_time" value="<fmt:formatDate value="${now}" pattern='yyyy-MM-dd'/>" onclick="init_datetimepicker_ymd_start()" /></div>
		       <span style="width: 5px;">-</span>
		      <div class="page_calendar_div"><input type="text" id="tx_end_time" class="page_calendar_input datetime_ymd_end" name="end_time" value="<fmt:formatDate value="${now}" pattern='yyyy-MM-dd' />" onclick="init_datetimepicker_ymd_end()" /></div>
			</label> 
			<button class="btn btn-success" type="button" id="" name="" onclick="gettxbcjllist();" ><i class="icon-search"></i>查询</button>
			<div class="break-br"></div>
			<button class="btn btn-danger btn_txbc_del" type="button" onclick="deltxbcjl();">删除</button>
			<button class="btn btn-info btn_txbc_add" type="button" onclick="addtxbcjlpage();">添加</button>
			<button class="btn btn-info btn_txbc_print" type="button" onclick="printBcjl();" id="print_btn">打印</button>
		  </div>
		  
		  <table class="table table-bordered table-responsive tx_bcjl_table">
	        <thead>
	        	<tr style="background-color:#E2EEED !important;background-image:none;">
	        		<td align="center">
	        			<div style="width: 45px"><input type="checkbox" id="selectallbox" name="selectallbox"></div>
	        		</td>
	        		<td align="center">记录时间</td>
	        		<td align="center">病程医生</td>
	        		<td align="center">病程名称</td>
	        	</tr>
	        </thead>
	        <tbody>
	         <tr><td style="width:45px;"></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
	         <tr><td style="width:45px;"></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
	         <tr><td style="width:45px;"></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
	         <tr><td style="width:45px;"></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
	        </tbody> 
          </table>
        </td>
        
        <td style="padding: 0px;width: 25px;background-color: #f0f0f0 !important;border-top:0;"><div style="width: 15px"></div></td> 
        
        <td style="padding: 0px;position: relative;" width="46%">
          <div class="txbc_content_title">病程内容</div>
          <div id="tx_bcjl_content" style="word-break:break-all;"></div>
          <div class="btn_txbcmuban_set" onclick="settxbcjlpage();">设置模板</button>
        </td>
       </tr>
      </table>
   </div>

   <div class="txbcjl_muban_set" style="display: none;text-align: center;margin-top: 20px;">
     <form class="form-inline">
       <div class="form-group">
	    <label for="tx_bc_mubanname" >模板名称:</label>
	    <input type="text" class="form-control" id="tx_bc_mubanname"  placeholder="请输入模板名称" value="" required="required" maxlength="30" style="min-width: 200px;">
	   </div>
	   <div style="text-align: center;margin-top: 25px;">
	     <button type="button" class="btn btn-success txbcmuban_confirm_btn" onclick="save_txbcmuban();" style="margin-right: 15px;">确认</button>
	     <button type="button" class="btn txbcmuban_cancle_btn"  style="background-color:#fff !important;margin-left: 15px;" onclick="">取消</button>
	   </div>
	 </form>  
   </div>
	<div id="print_wrapper_clone" style="display: none;"></div>
	<script type="text/template" id='tpl_print_bcjl'>

		<table border="0" style="font-size:9pt;" width="100%" align="center">
            <thead style="display:table-header-group;font-weight:bold">
            <tr>
            <td colspan="4" align="center" style="font-weight:bold;border:3px double red">{{hos_name}}</td>
            </tr>
            <tr>
            <td>姓名：{{ hzinfo.tx_name}} </td>
            <td>病区：{{ hzinfo.tx_bing_qu}} </td>
            <td>床号：{{ hzinfo.tx_bed_number}} </td>
            <td>住院号：{{ hzinfo.tx_zyid}} </td>
            </tr>
            </thead>
            <tbody id="txbc_print_tbody">               </tbody>
            </table>
	</script>
	<script src="js/common/template-web.js"></script>
	<script src="js/common/jQuery.print.js"></script>	
	<script type="text/javascript">
	  $(function() {
	     init_datetimepicker_ymd_start();
		 init_datetimepicker_ymd_end();
		 getallbcjl();	
			
	  });
	  
	 //获取所有的病程记录 
	 function getallbcjl(){
	     $.post("manage/txbcjl.shtml",{tx_number:"${param.sk_hzid}",tx_start_time:"",tx_end_time:""},function(data){
	          $("table.tx_bcjl_table>tbody").empty();
	             if(data.res==null||data.res.length==0){
	                $("table.tx_bcjl_table>tbody").append(
	                   "<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                  +"<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                  +"<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                  +"<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                );
	                return false;
	             }
	             $.each(data.res,function(index,item){
	             	var bc_content = item.bc_CONTENT.replace(/script/g,"span");
	                 $("table.tx_bcjl_table>tbody").append(
	                   "<tr class='txbc_tr' data-id="+item.tx_id+" data-bccontent='"+bc_content+"'><td style='width:45px;'><input type='checkbox' name='patientcheck' value=''></td><td>"+(item.recording_DATE==null?"":item.recording_DATE.substring(0,19))+"</td><td>"+item.bc_DOCTOR+"</td><td>"+item.bc_NAME+"</td></tr>"
	                 );
	             }); 
	             try {$("table.tx_bcjl_table>tbody tr.txbc_tr").eq(0).trigger("click")} catch (e){}        
	      });
	 }  
	  
	  //获取病程记录
	  function gettxbcjllist(){
	     $.post("manage/txbcjl.shtml",{tx_number:"${param.sk_hzid}",tx_start_time:$("#tx_start_time").val(),tx_end_time:$("#tx_end_time").val()},function(data){
	          $("table.tx_bcjl_table>tbody").empty();
	             if(data.res==null||data.res.length==0){
	                $("table.tx_bcjl_table>tbody").append(
	                   "<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                  +"<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                  +"<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                  +"<tr><td style='width:45px;'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
	                );
	                return false;
	             }
	             $.each(data.res,function(index,item){
	             	 var bc_content = item.bc_CONTENT.replace(/script/g,"span");
	                 $("table.tx_bcjl_table>tbody").append(
	                   "<tr class='txbc_tr' data-id="+item.tx_id+" data-bccontent='"+bc_content+"'><td style='width:45px;'><input type='checkbox' name='patientcheck' value=''></td><td>"+(item.recording_DATE==null?"":item.recording_DATE.substring(0,19))+"</td><td>"+item.bc_DOCTOR+"</td><td>"+item.bc_NAME+"</td></tr>"
	                 );
	             });
	             try {$("body table.tx_bcjl_table>tbody tr.txbc_tr").eq(0).trigger("click")} catch (e){}          
	      });
	  }	
	  
	  //点击病程记录
	  $("body").on("click","tr.txbc_tr",function(){
	      $(this).addClass("txbc_tr_active").siblings().removeClass("txbc_tr_active");
	      var s=$(this).attr("data-bccontent");
	        var s1 = s.substring(0, s.indexOf(",-_"));
			var s2 = s.substring(s.indexOf(",-_") + 3, s.lastIndexOf(",-_"));
			var s3 = s.substring(s.lastIndexOf(",-_") + 3);
			if(s.indexOf(",-_")=="-1"){
			   $("#tx_bcjl_content").html(s);
			}else{
			   if(s2==""&& s3!=""){
			     //评估后		       
			    var t=s3.split(",");		     
			   	$("#tx_bcjl_content").html("<br><lable><b>透后评估:</b>&nbsp;&nbsp;&nbsp;T(℃):"+t[0]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;P(次/分)："+t[1]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R(次/分)："+t[2]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BP(mmhg)："+t[3]+"/"+t[4]+"</lable><br><br>"
			   		                             +"<lable>"+s1+"</lable>");		  		   
			   }else if(s2!=""&& s3==""){
			      //评估前
			      var t1=s2.split(",");
			      $("#tx_bcjl_content").html("<br><lable><b>透前评估:</b>&nbsp;&nbsp;&nbsp;T(℃):"+t1[0]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;P(次/分)："+t1[1]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R(次/分)："+t1[2]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BP(mmhg)："+t1[3]+"/"+t1[4]+"</lable><br><br>"
			   		                             +"<lable>"+s1+"</lable>");
			   }else{
			      var t2=s3.split(",");
			      var t3=s2.split(",");
			          $("#tx_bcjl_content").html("<br><lable><b>透前评估:</b>&nbsp;&nbsp;&nbsp;T(℃):"+t3[0]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;P(次/分)："+t3[1]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R(次/分)："+t3[2]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BP(mmhg)："+t3[3]+"/"+t3[4]+"</lable><br>"
			                                        +"<lable><b>透后评估:</b>&nbsp;&nbsp;&nbsp;T(℃):"+t2[0]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;P(次/分)："+t2[1]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R(次/分)："+t2[2]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BP(mmhg)："+t2[3]+"/"+t2[4]+"</lable><br><br>"
			                                    +"<lable>"+s1+"</lable>"
			          );
			            
			   }
		}	     
	      
	    /*   $("#tx_bcjl_content").html($(this).attr("data-bccontent")); */
	  });
	  
	  //双击修改病程记录
	  var dbtxbcjl_index=null;
	  $("table.tx_bcjl_table").on("dblclick","tr",function(){
	     $(this).addClass("txbc_tr_active").siblings().removeClass("txbc_tr_active");
	   //  $("#tx_bcjl_content").html($(this).attr("data-bccontent"));
	     dbtxbcjl_index=layer.open({
	        title:'修改病程内容',
		    type: 2,
		    closeBtn: 1,
		    anim: 2,
		    shadeClose: true,
		    skin:'layui-layer-skgeen',
		    area: ['800px', '626px'],
		    content: 'manage/txbcjlupdatepage.shtml?sk_hzid=${param.sk_hzid}&tx_id='+$(this).attr("data-id")
		 });
	  });
	  
	  
	  //添加病程
	  var addtxbcjl_index=null;
	  function addtxbcjlpage(){
	       addtxbcjl_index=layer.open({
		        title:'添加病程内容',
			    type: 2,
			    closeBtn: 1,
			    anim: 2,
			    shadeClose: true,
			    skin:'layui-layer-skgeen',
			    area: ['800px', '626px'],
			    content: 'manage/txbcjlupdatepage.shtml?sk_hzid=${param.sk_hzid}&tx_id='
			 });
	  }
	  
	  
	  //删除病程记录
	  var deltipspage=null;
	  function deltxbcjl(){
	     var tx_id=$("table.tx_bcjl_table").find("tr.txbc_tr_active").attr("data-id");
	     if(typeof(tx_id)=="undefined"){layer.msg("请先选择病程记录！");return false;}
	     deltipspage=layer.confirm('确认删除该病程记录？', {
		    btn: ['确定','取消'],title:'温馨提示',closeBtn: 0,anim: 2,shadeClose: true,skin:'layui-layer-skgeen'
			}, function(){
			     $.post("manage/deletetxbcjl.shtml?tx_id="+tx_id,function(){
			        layer.msg("删除成功！");
			        $("#tx_bcjl_content").html("");
			        parent.gettxbcjllist();
			     });		
			}, function(){
			   layer.close(deltipspage);
		 });
	  }
	  	 
	  //模板设置页面
	  var settxbcjl_index=null;
	  function settxbcjlpage(){
	       if(""==$("#tx_bcjl_content").text()){layer.msg("请先选择病程记录！");return false;}
	       settxbcjl_index=layer.open({
		        title:'设置模板名称',
			    type: 1,
			    closeBtn: 1,
			    anim: 2,
			    shadeClose: true,
			    skin:'layui-layer-skgeen',
			    area: ['300px', '200px'],
			    content: $('.txbcjl_muban_set')
			 });
			 $("button.txbcmuban_cancle_btn").attr("onclick","layer.close("+settxbcjl_index+");")
	  }	 
	  
	  //保存病程模板
	  function save_txbcmuban(){
	    if(""==$("#tx_bc_mubanname").val()){
	       layer.msg("模板名称不能为空！");    
	    }else{
	       $.post("manage/savetxbcjl_muban.shtml",{name_t:$("#tx_bc_mubanname").val(),content_t:$("#tx_bcjl_content").html()},function(data){
	          if(1==data.res){layer.msg("设置成功！");}else{layer.msg("设置失败！");}
	          layer.close(settxbcjl_index);
	       });
	    }
	  }
	  	  
	  function init_datetimepicker_ymd_start(){
	   $(".datetime_ymd_start").datetimepicker({
	        format: 'yyyy-mm-dd',
	        language:  'zh-CN',
	        weekStart: 1,
	        todayBtn:  1,
			autoclose: 1,
			todayHighlight: true,
			startView: 2,
			minView: 2,
			forceParse: 0,
			keyboardNavigation:1,
			forceParse:1
	    }).on("click",function(){
	       $(".datetime_ymd_start").datetimepicker("setEndDate",$("input[name='end_time']").val());
	    });
	   }
	   
	   function init_datetimepicker_ymd_end(){
	     $(".datetime_ymd_end").datetimepicker({
	        format: 'yyyy-mm-dd',
	        language:  'zh-CN',
	        weekStart: 1,
	        todayBtn:  1,
			autoclose: 1,
			todayHighlight: true,
			startView: 2,
			minView: 2,
			forceParse: 0,
			keyboardNavigation:1,
			forceParse:1
	     }).on("click",function(){
	       $(".datetime_ymd_end").datetimepicker("setStartDate",$("input[name='start_time']").val());
	     });
	   }
		
	   function getNowDate() {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1; if (month >= 1 && month <= 9) {month = "0" + month;}
		    var strDate = date.getDate(); if (strDate >= 0 && strDate <= 9){strDate = "0" + strDate;}
		    var h=date.getHours();if(h>=0&&h<10){ h="0"+h;}
		    var i=date.getMinutes();if(i >= 0 && i <= 9) { i = "0" + i;}
		    var s=date.getSeconds(); if(s >= 0 && s <= 9) {s="0"+s;}
		    var currentdate = date.getFullYear() + seperator1 + month
		            + seperator1 + strDate
		            + " " + h + seperator2 + i
		            + seperator2 + s;
		    return currentdate;
		}
		function getNowMonthFirstDate() {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1; if (month >= 1 && month <= 9) {month = "0" + month;}
		    var currentdate = date.getFullYear() + seperator1 + month
		            + seperator1 + "01"
		    return currentdate;
		}
		
		// 病程打印
		var tx_number = $("#left_sk_hzid").val();
		var tx_record_id = [];
		function printBcjl(){
			if($("input[name='patientcheck']:checked").length == 0){
				layer.msg("请勾选需要打印的病程记录")
				return false;
			}
			$("input[name='patientcheck']:checked").each(function(v,i){
				var record_id = $(this).parent().parent().data("id");
				tx_record_id.push(record_id)
			})
			$.ajax({
                url: "bcjldy/dybcjllist.shtml",
                type: "POST",
                data: {
                    "tx_number": tx_number,
                    "tx_start_time": "",
                    "tx_end_time": "2018-02-08"
                },
                success: function (res) {
                    console.log(res)
                    var printHtml= template("tpl_print_bcjl",res);
                    console.log(printHtml)
                    
				    var startStr = '<table border="0" style="font-size:9pt;" width="100%" align="center">' +
					            '<thead style="display:table-header-group;font-weight:bold">' +
					            '<tr>' +
					            '<td colspan="4" align="center" style="font-weight:bold;border:3px double red">每页都有的表头</td>' +
					            '</tr>' +
					            '<tr>' +
					            '<td>姓名：' + res.hzinfo.tx_name + '</td>' +
					            '<td>病区：' + res.hzinfo.tx_bing_qu + '</td>' +
					            '<td>床号：' + res.hzinfo.tx_bed_number + '</td>' +
					            '<td>住院号：' + res.hzinfo.tx_zyid + '</td>' +
					            '</tr>' +
					            '</thead>' +
					            '<tbody>';
		            var endStr = '</tbody>' +
					            '</table>';
					var str = '';
					$("input[name='patientcheck']:checked").each(function(v,i){
						var record_time = ($(this).parent().parent().children('td').eq(1).text()).substring(0,16);
						var record_content = $(this).parent().parent().data("bccontent");
						var record_name = $(this).parent().parent().children('td').eq(3).text();
						var content = '<tr class="course-name"><td colspan="4"><span style="margin-right:60px;">'+ record_time +'</span>' + record_name + '</td></tr>'+
									  '<tr class="course-content"><td colspan="4">'+ record_content + '</td></tr>'+
									  '<tr class="doctor-sign"><td colspan="4">医师签名：    </td></tr>';
						  str += content;
						 // $("#txbc_print_tbody").append(content)
						//console.log(record_time,record_content,record_name)
					})
					//startStr += endStr;
					/* $("#print_wrapper_clone").append(printHtml)
					$("#txbc_print_tbody").append(str)
					layer.open({
							title: ['打印', 'font-size:18px;background:#22C6B7;color:#fff;'],
							type: 1,
							area: ['836px', '860px'],
							resize: false,		
							content: $("#print_wrapper_clone").html()		
						}); */
                },
                error: function (res) {
                    console.log(res);
                }
            });
			
			
			var tx_start_time = $("#tx_start_time").val(),
				tx_end_time = $("#tx_end_time").val(),
				tx_record_id_str = tx_record_id.toString()
			console.log({"tx_number":tx_number,"tx_start_time":tx_start_time,"tx_end_time":tx_end_time})
			window.open('jsp/renal/tx_bcjl_print.html?tx_number='+tx_number+'&tx_start_time='+tx_start_time+'&tx_end_time='+tx_end_time+'&tx_id='+tx_record_id_str,'_blank');
			return;
			
		}
	</script>
	
